package com.moody.hibernate.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.moody.hibernate.domain.CustManager;

/**
 * A data access object (DAO) providing persistence and search support for
 * CustManager entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.moody.hibernate.domain.CustManager
 * @author MyEclipse Persistence Tools
 */

public class CustManagerDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(CustManagerDAO.class);
	// property constants
	public static final String CUST_ID = "custId";
	public static final String MANAGER_NAME = "managerName";
	public static final String IDTYPE = "idtype";
	public static final String MANAGER_ID = "managerId";
	public static final String SEX_TYPE = "sexType";
	public static final String JOBTITLE = "jobtitle";
	public static final String NATIONALITY = "nationality";
	public static final String CELL_NO = "cellNo";
	public static final String TEL_NO = "telNo";
	public static final String FAX_NO = "faxNo";
	public static final String EMAIL = "email";
	public static final String EDUCATION = "education";
	public static final String BIRTHDAY = "birthday";
	public static final String WORK_START = "workStart";
	public static final String INPUT_USER_ID = "inputUserId";
	public static final String INPUT_ORG_ID = "inputOrgId";
	public static final String INPUT_DATE = "inputDate";
	public static final String UPDATE_USER_ID = "updateUserId";
	public static final String UPDATE_ORG_ID = "updateOrgId";
	public static final String UPDATE_DATE = "updateDate";

	protected void initDao() {
		// do nothing
	}

	public void save(CustManager transientInstance) {
		log.debug("saving CustManager instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(CustManager persistentInstance) {
		log.debug("deleting CustManager instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public CustManager findById(java.lang.String id) {
		log.debug("getting CustManager instance with id: " + id);
		try {
			CustManager instance = (CustManager) getHibernateTemplate().get(
					"com.moody.hibernate.domain.CustManager", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(CustManager instance) {
		log.debug("finding CustManager instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding CustManager instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from CustManager as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCustId(Object custId) {
		return findByProperty(CUST_ID, custId);
	}

	public List findByManagerName(Object managerName) {
		return findByProperty(MANAGER_NAME, managerName);
	}

	public List findByIdtype(Object idtype) {
		return findByProperty(IDTYPE, idtype);
	}

	public List findByManagerId(Object managerId) {
		return findByProperty(MANAGER_ID, managerId);
	}

	public List findBySexType(Object sexType) {
		return findByProperty(SEX_TYPE, sexType);
	}

	public List findByPosition(Object jobtitle) {
		return findByProperty(JOBTITLE, jobtitle);
	}

	public List findByNationality(Object nationality) {
		return findByProperty(NATIONALITY, nationality);
	}

	public List findByCellNo(Object cellNo) {
		return findByProperty(CELL_NO, cellNo);
	}

	public List findByTelNo(Object telNo) {
		return findByProperty(TEL_NO, telNo);
	}

	public List findByFaxNo(Object faxNo) {
		return findByProperty(FAX_NO, faxNo);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findByEducation(Object education) {
		return findByProperty(EDUCATION, education);
	}

	public List findByBirthday(Object birthday) {
		return findByProperty(BIRTHDAY, birthday);
	}

	public List findByWorkStart(Object workStart) {
		return findByProperty(WORK_START, workStart);
	}

	public List findByInputUserId(Object inputUserId) {
		return findByProperty(INPUT_USER_ID, inputUserId);
	}

	public List findByInputOrgId(Object inputOrgId) {
		return findByProperty(INPUT_ORG_ID, inputOrgId);
	}

	public List findByInputDate(Object inputDate) {
		return findByProperty(INPUT_DATE, inputDate);
	}

	public List findByUpdateUserId(Object updateUserId) {
		return findByProperty(UPDATE_USER_ID, updateUserId);
	}

	public List findByUpdateOrgId(Object updateOrgId) {
		return findByProperty(UPDATE_ORG_ID, updateOrgId);
	}

	public List findByUpdateDate(Object updateDate) {
		return findByProperty(UPDATE_DATE, updateDate);
	}

	public List findAll() {
		log.debug("finding all CustManager instances");
		try {
			String queryString = "from CustManager";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public CustManager merge(CustManager detachedInstance) {
		log.debug("merging CustManager instance");
		try {
			CustManager result = (CustManager) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(CustManager instance) {
		log.debug("attaching dirty CustManager instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(CustManager instance) {
		log.debug("attaching clean CustManager instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CustManagerDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (CustManagerDAO) ctx.getBean("CustManagerDAO");
	}

	public void update(CustManager custManager) {
		log.debug("saving CustManager instance");
		try {
			getHibernateTemplate().update(custManager);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
		
	}
}